package com.hxd.otc.module.my.activity;

import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.contrarywind.view.WheelView;
import com.hxd.otc.R;
import com.hxd.otc.base.BaseRecyclerActivity;
import com.hxd.otc.module.my.adapter.MerchantsOrderAdapter;
import com.hxd.otc.module.my.bean.MerchantsOrderBean;
import com.hxd.otc.module.my.contract.MerchantsOrderContract;
import com.hxd.otc.module.my.presenter.MerchantsOrderPresenter;
import com.hxd.otc.utils.DateUtil;
import com.hxd.otc.utils.ResourceUtil;

import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/8/14 0014.
 * description ${商户订单}
 */
public class MerchantsOrderActivity extends BaseRecyclerActivity<MerchantsOrderPresenter, MerchantsOrderAdapter, MerchantsOrderBean> implements MerchantsOrderContract.View {

    @BindView(R.id.tv_month)
    TextView mTvMonth;
    private TimePickerView mTimePickerView;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_merchats_order;
    }

    @Override
    protected void initData() {
        super.initData();
        updateTvMonth();
    }

    private void updateTvMonth() {
        mTvMonth.setText(DateUtil.format(mPresenter.getCreateTime(), getString(R.string.my_merchats_order_month_format)));
    }

    @Override
    protected MerchantsOrderAdapter createAdapter() {
        return new MerchantsOrderAdapter(this);
    }

    @Override
    protected MerchantsOrderPresenter createPresenter() {
        return new MerchantsOrderPresenter(this);
    }

    @OnClick({R.id.iv_picker_date})
    public void onClick(View view) {
        //选中事件回调
        mTimePickerView = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                mPresenter.setCreateTime(date);
                mRefreshLayout.autoRefresh(0, 10, 1);
                updateTvMonth();
            }
        }).isCenterLabel(false)
                .setTextXOffset(100, 0, 0, 0, 0, 0)
                .setLineSpacingMultiplier(2f)
                .setCancelColor(ResourceUtil.getColor(R.color.color_FFD2A56B))
                .setSubmitColor(ResourceUtil.getColor(R.color.color_FFD2A56B))
                .setDividerType(WheelView.DividerType.WRAP)
                .setType(new boolean[]{true, true, false, false, false, false})
                .build();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(mPresenter.getCreateTime());
        mTimePickerView.setDate(calendar);//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        mTimePickerView.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mTimePickerView != null) {
            mTimePickerView.dismiss();
            mTimePickerView = null;
        }
    }
}
